import { proxy } from 'valtio';
import { get, post } from "../request"
interface DataType {
    key: string;
    brand?: string;// 品牌
    shop?: string;// 店铺
    platform: string;// 订单来源
    order: number;// 订单总量
    unSettled: number; // 未结算订单
    settled: number;// 已结算订单
    returnOrder: number;// 退订订单
    total: number; // 总营业额
    settledAmount: number;// 已结算金额
    paidAmount: number;//实付金额
    delivery: number;// 配送费
    platforms: number;//平台补贴
    service: number; // 服务费
    children?: DataType[]; // 子集
    date: string; // 日期
}

export const Finance1 = proxy({
    data: [] as DataType[],
    brand: "",
    partition: "",
    shop: "",
    platform: "",
    date: "",
    today:"",
    FinanceTrend: {
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [
            {   
                name: "订单总量",
                emphasis: {
                    focus:"series"
                },
                data: [],
                type: "bar",
                stack: "x"
            },
            {   
                name: "未结算订单",
                emphasis: {
                    focus:"series"
                },
                data: [],
                type: "bar",
                stack: "x"
            },
            {   
                name: "已结算订单",
                emphasis: {
                    focus:"series"
                },
                data: [],
                type: "bar",
                stack: "x"
            },
            {   
                name: "退订订单",
                emphasis: {
                    focus:"series"
                },
                data: [],
                type: "bar",
                stack: "x"
            },
        ],
        legend: {
            data:[],
            show:true
        }
    },
    getArgs: (brand: string, partition: string, shop: string, platform: string, date: string,today:string) => {
        Finance1.brand = brand
        Finance1.partition = partition
        Finance1.shop = shop
        Finance1.platform = platform
        Finance1.date = date
        Finance1.today = today
    },
    getList: () => {
        get("/finance").then((res:any) => {
            Finance1.data = res.data as DataType[]
            Finance1.FinanceTrend.xAxis.data = res.FinanceTrend.xAxis.data
            Finance1.FinanceTrend.series[0].data = res.FinanceTrend.series[0].data
            Finance1.FinanceTrend.series[1].data = res.FinanceTrend.series[1].data
            Finance1.FinanceTrend.series[2].data = res.FinanceTrend.series[2].data
            Finance1.FinanceTrend.series[3].data = res.FinanceTrend.series[3].data
        })
    },
    search: () => {
        post("/finance/search", {
            brand: Finance1.brand,
            partition: Finance1.partition,
            shop: Finance1.shop,
            platform: Finance1.platform,
            date: Finance1.date,
            today:Finance1.today
        }).then((res:any) => {
            Finance1.data = res.data as DataType[]
            console.log(res.FinanceTrend)
            Finance1.FinanceTrend.xAxis.data = res.FinanceTrend.xAxis.data
            Finance1.FinanceTrend.series[0].data = res.FinanceTrend.series[0].data
            Finance1.FinanceTrend.series[1].data = res.FinanceTrend.series[1].data
            Finance1.FinanceTrend.series[2].data = res.FinanceTrend.series[2].data
            Finance1.FinanceTrend.series[3].data = res.FinanceTrend.series[3].data
            Finance1.FinanceTrend.legend.data = res.FinanceTrend.legend.data
            
            console.log(res.FinanceTrend)
        })
    }


})